// pages/goods/received/received.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  onLoad: function (options) {
    //通过orderId 获取订单数据详情
    this.getOrderDetailById(options.order_id);
  },

  getOrderDetailById: function (order_id) {
    app.Ajax({
      url: '/api/index.php?app=order&act=detail',
      data: {
        order_id: order_id
      },
      success: (res) => {
        let barTitle = '';
        switch (res.status) {
          case 10: barTitle = '待付款'; break;
          case 20: barTitle = '待发货'; break;
          case 30: barTitle = '待收货'; break;
          case 40: barTitle = '已收货'; break;
        }
        wx.setNavigationBarTitle({
          title: barTitle
        })
        let logistics = [];
        if (res.express) {
          logistics = res.express.data;
        }
        if (res.status === 30 || res.status === 40) {
          this.setData({
            hasSend: true,
            shipping_name: res.shipping_name,
            shipping_no: res.shipping_no,
            ship_time: res.ship_time
          })
        }
        this.setData({
          currentGoods: res.goods[0],
          logistics: logistics
        })
      },
      fail: (err) => {

      }
    })
  },
  data: {
    ship_time: '',//发货时间
    shipping_no: '',//运单号码
    shipping_name: '',//物流公司
    currentGoods: {},//当前商品的信息
    hasSend: false,
    logistics: [],//物流信息列表
  },
})